package com.jic.market.controller.manage;

import com.jic.common.base.vo.RestResult;

import com.jic.market.entity.TagCategory;
import com.jic.market.request.PromotionRequest;
import com.jic.market.request.manager.presell.PromotionPresellCopyRequest;
import com.jic.market.request.manager.xoffer.PromotionXofferCopyRequest;
import com.jic.market.response.PromotionManagerResponse;
import com.jic.market.response.PromotionResponse;
import com.jic.market.service.JicMarketPromotionService;
import com.jic.market.service.xoffer.PromotionXofferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * date: 2020-03-5 18:20
 * author: wj
 * version: 1.0
 */
@RestController
@RequestMapping("promotionSingleProduct")
@Api(tags = {"单品X件优惠"})
@Slf4j
public class PromotionSingleProductController {
    @Autowired
    JicMarketPromotionService jicMarketPromotionService;
    @Autowired
    PromotionXofferService promotionXofferService;

    @ApiOperation(value = "添加单品X件优惠")
    @PostMapping(value = "/savePromotionSingleProduct")

    @ResponseBody
    public RestResult<Long> savePromotionSingleProduct(@RequestBody PromotionRequest request) {
        return RestResult.success(jicMarketPromotionService.savePromotionSingleProduct(request).getId());
    }



   /*
   * 单品X件详情
   * */
    @ApiOperation(value = "查询单品X件优惠详情")
    @PostMapping(value = "/queryPromotionDetail")
    @ResponseBody
    public RestResult<PromotionManagerResponse> queryPromotionDetail(@RequestBody PromotionRequest request) {
        PromotionManagerResponse promotionManagerResponse=jicMarketPromotionService.queryPromotionDetail(request.getId());
        return  RestResult.success(promotionManagerResponse);
    }


    @ApiOperation(value = "删除单品X件促销")
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public RestResult<Long> delete(@RequestBody PromotionRequest param){
        return  jicMarketPromotionService.delSingleProduct(param);
    }

    @ApiOperation(value = "关闭单品X件促销")
    @RequestMapping(value = "closeXofferPromotion",method = RequestMethod.POST)
    public RestResult<Long> closeXofferPromotion(@RequestBody PromotionRequest param){
        return  jicMarketPromotionService.closeXofferPromotion(param);
    }

    @ApiOperation(value = "复制单品X件促销")
    @RequestMapping(value = "copyXofferPromotion",method = RequestMethod.POST)
    public RestResult<Long> copyXofferPromotion(@RequestBody PromotionXofferCopyRequest param) {
        return promotionXofferService.copyXofferPromotion(param);
    }

    @ApiOperation(value = "保存为模板")
    @PostMapping("saveXofferTemplate")
    public RestResult<Long> saveTemplate(@RequestBody PromotionXofferCopyRequest request) {
        return promotionXofferService.saveTemplate(request);
    }



}
